home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 26 / develop issue 26 code / truffles - display mgr. / sprocket / sources / dragutils.cp < prev    next >
Encoding:
Text File  |  1995-01-03  |  2.9 KB  |  118 lines

  1. /*
  2.     File:        DragUtils.cp
  3.  
  4.     Contains:    Useful utility functions when using the Drag Manager.
  5.  
  6.     Written by: Nitin Ganatra
  7.  
  8.     Copyright:    © 1993-1995 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.          <3>      1/3/95    DRF        Replace everything with Nitin’s code.
  13.          <2>    11/12/94    DRF        Added #include to pick up function prototype.
  14.          <1>      9/9/94    DRF        first checked in
  15.  */
  16.  
  17. #include "Sprocket.h"
  18.  
  19. #include <Folders.h>
  20.  
  21. #include <QuickDraw.h>
  22. #include <Folders.h>
  23. #include <Files.h>
  24. #include <Drag.h>
  25.  
  26.  
  27. //-----------------------------------------------------------------------------
  28. // The standard UI for dragged objects is a 1-pixel outline of 
  29. // region to be dragged.
  30. // Given any region, this will turn it into the 1-pixel outline.
  31. //-----------------------------------------------------------------------------
  32. void MakeDragOutlineRegion(RgnHandle theRgn)
  33. {
  34.     RgnHandle tempRgn;
  35.     
  36.     tempRgn = NewRgn();
  37.  
  38.     if (tempRgn != NULL) {
  39.         CopyRgn(theRgn, tempRgn);
  40.         InsetRgn(tempRgn, 1, 1);
  41.         DiffRgn(theRgn, tempRgn, theRgn);
  42.         DisposeRgn(tempRgn);
  43.     }
  44. }
  45.  
  46.  
  47. //-----------------------------------------------------------------------------
  48. // GetDropDirectory
  49. //
  50. // Given a DragReference, this returns an FSSpec for the directory where the 
  51. // item was dropped.
  52. //-----------------------------------------------------------------------------
  53. OSErr GetDropDirectory(DragReference theDrag, FSSpecPtr dirSpec)
  54. {
  55.     OSErr    returnCode;
  56.     AEDesc    theDesc;
  57.  
  58.     returnCode = GetDropLocation(theDrag, &theDesc);
  59.  
  60.     if ((theDesc.dataHandle != nil) 
  61.             && (returnCode == noErr)) {
  62.         AEDesc newDesc;
  63.  
  64.         returnCode = AECoerceDesc(&theDesc, typeFSS, &newDesc);
  65.  
  66.         if (returnCode == noErr) {
  67.             BlockMoveData(*newDesc.dataHandle, dirSpec, sizeof(FSSpec));
  68.             (void) AEDisposeDesc(&newDesc);
  69.         }
  70.  
  71.         (void) AEDisposeDesc(&theDesc);
  72.     }
  73.  
  74.     return returnCode;
  75. }
  76.  
  77.  
  78. //-----------------------------------------------------------------------------
  79. // DragLandedInTrash
  80. //
  81. // If this drag landed in the trash (compared using FindFolder) this will
  82. // return true.
  83. //-----------------------------------------------------------------------------
  84. Boolean DragLandedInTrash(DragReference theDrag)
  85. {
  86.     OSErr    returnCode;
  87.     FSSpec    dirSpec;
  88.     short    trashVol;
  89.     long    trashDirID;
  90.     Boolean    wasTrashed;
  91.  
  92.     wasTrashed = false;
  93.     returnCode = GetDropDirectory(theDrag, &dirSpec);
  94.  
  95.     if (returnCode == noErr) {    
  96.         returnCode = FindFolder(0, kTrashFolderType, false, &trashVol, &trashDirID);
  97.         
  98.         if (returnCode == noErr) {
  99.             CInfoPBRec    catInfo;
  100.             DirInfo        *dpb = (DirInfo    *)&catInfo;
  101.             
  102.             dpb->ioCompletion = nil;            // Find the dirID of the drop location,
  103.             dpb->ioNamePtr = dirSpec.name;        // not its parent.
  104.             dpb->ioVRefNum = dirSpec.vRefNum;
  105.             dpb->ioDrDirID = dirSpec.parID;
  106.             dpb->ioFDirIndex = 0;
  107.         
  108.             returnCode = PBGetCatInfoSync((CInfoPBPtr)dpb);
  109.             
  110.             if ((trashVol == dirSpec.vRefNum) 
  111.                 && (trashDirID == dpb->ioDrDirID))
  112.                 wasTrashed = true;
  113.         }
  114.     }
  115.  
  116.     return wasTrashed;
  117. }
  118.